home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: jlilley@ix.netcom.com (John Lilley)
- Newsgroups: comp.lang.c++
- Subject: Re: How to simulate EOF from the keyboard in Visual C++ 4.0, CTRL+Z doesn't work well
- Date: 18 Mar 1996 17:54:38 GMT
- Organization: Netcom
- Message-ID: <4ik80u$14k@reader2.ix.netcom.com>
- References: <314CB927.22A3@cco.caltech.edu>
- NNTP-Posting-Host: den-co8-14.ix.netcom.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
- X-NETCOM-Date: Mon Mar 18 9:54:38 AM PST 1996
- X-Newsreader: WinVN 0.99.7
-
- In article <314CB927.22A3@cco.caltech.edu>, xuhua@cco.caltech.edu says...
- >
- >The title says everything. When I try to simulate the EOF from the
- >keyboard in Visual C++ with CTRL+Z, it doesn't work. CTRL+Z just kill
- >the running program. I am running windows 95.
- >Please try the following simple program from <<C++ Primer Plus>>:
- >
- >Program #1
- >// textin3.cpp -- reading chars to end of file
- >#include <iostream.h>
- >int main(void)
- >{
- > char ch;
- > int count = 0;
- >
- > while (cin.get(ch)) // cin.get(ch) is 0 on EOF
- > {
- > cout << ch;
- > count++;
- > }
- > cout << count << " characters read\n";
- > return 0;
- >}
- >
-
- When I do this with Viaul C++, hitting CTRL-Z does end the program
- without flushing the output. Even adding cout.flush() does not
- improve matters. However, if you add logic to end the loop for
- some other reason, such as encountering a 'q' key, it is fine,
- which leads me to believe that the DOS emulation in either VC++
- or Windows95 is closing cout when the EOF is encountered for cin.
-
- When this is compiled and run using Borland 4.5 it works
- (i.e., prints the count), so it sounds like a bug in the VC++
- cin/cout command-line emulation.
-
- john lilley
-
-